package com.hd.sup.modules.vehicle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hd.common.utils.GenUtil;
import com.hd.sup.modules.vehicle.model.VehicleOnOff;
import com.hd.sup.modules.vehicle.mapper.VehicleOnOffMapper;
import com.hd.sup.modules.vehicle.service.IVehicleOnOffService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 车辆离线、在线状态 服务实现类
 * </p>
 *
 * @author chentl123
 * @since 2020-12-28
 */
@Service
public class VehicleOnOffServiceImpl extends ServiceImpl<VehicleOnOffMapper, VehicleOnOff> implements IVehicleOnOffService {

    @Override
    public List<Map<String, Object>> getVehicleDrivingPage(Page<Map<String, Object>> page, VehicleOnOff vehicleOnOff) {
        return this.baseMapper.getVehicleDrivingPage(page, vehicleOnOff);
    }

    @Override
    public void syncData(VehicleOnOff bo) {
        VehicleOnOff db = getOne(new LambdaQueryWrapper<VehicleOnOff>().eq(VehicleOnOff::getPlatNo, bo.getPlatNo()).eq(VehicleOnOff::getPlatNoColor, bo.getPlatNoColor()));
        if (db == null) {
            bo.setId(GenUtil.newId());
            bo.insert();
        } else {
            db.setOnlineTime(bo.getOnlineTime());
            db.setOnlineStatus(bo.getOnlineStatus());
            db.setOffTime(bo.getOffTime());
            db.setDuration(bo.getDuration());
            db.setDistance(bo.getDistance());
            db.updateById();
        }
    }
}
